package kr.hkit.ch09;

import com.example.androidcompletelka.R;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Button;

public class MenuEditEx extends Activity {
	String TAG = "MenuEditEx";

	Button mBtn;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		Log.d(TAG, "onCreate()");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu_editex);

		mBtn = (Button) findViewById(R.id.ch09_menueditex_btn);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_edit, menu);
		return true;
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		Log.d(TAG, "onCreate()");
		
		if (mBtn.getTextSize() == 40) {
			menu.findItem(R.id.ch09_menuedit_higfont).setChecked(true);
		} else {
			menu.findItem(R.id.ch09_menuedit_higfont).setChecked(false);
		}
		int color = mBtn.getTextColors().getDefaultColor();
		if (color == Color.RED) {
			menu.findItem(R.id.ch09_menuedit_red).setChecked(true);
		}
		if (color == Color.GREEN) {
			menu.findItem(R.id.ch09_menuedit_green).setChecked(true);
		}
		if (color == Color.BLUE) {
			menu.findItem(R.id.ch09_menuedit_blue).setChecked(true);
		}

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Log.d(TAG, "onOptionsItemSelected()");
		
		switch (item.getItemId()) {
		case R.id.ch09_menuedit_higfont:

			if (item.isChecked()) {
				mBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, 20);
			} else {
				mBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, 40);

			}
			return true;
		
		case R.id.ch09_menuedit_red:
			mBtn.setTextColor(Color.RED);
			return true;
		case R.id.ch09_menuedit_green:
			mBtn.setTextColor(Color.GREEN);
			return true;
		case R.id.ch09_menuedit_blue:
			mBtn.setTextColor(Color.BLUE);
			return true;

		}
		return false;
	}

}
